package com.managertrade.dao.mysql.repository;

import com.managertrade.dao.mysql.entity.UserFollowTrader;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

public interface UserFollowTraderRepository extends JpaRepository<UserFollowTrader, Long> {
    boolean existsByUserIdAndLeadTraderId(Long userId, String leadTraderId);
    void deleteByUserIdAndLeadTraderId(Long userId, String leadTraderId);
    List<UserFollowTrader> findByUserId(Long userId);

    // 🔍 根据用户ID和交易员唯一标识（leadTraderId / uniqueCode）查找一条数据
    Optional<UserFollowTrader> findByLeadTraderId(String leadTraderId);

    /**
     * 根据用户ID和交易员唯一标识码查找单条跟单记录
     */
    Optional<UserFollowTrader> findByUserIdAndLeadTraderId(Long userId, String leadTraderId);



    // 按 uniqueCode 批量查询
    List<UserFollowTrader> findByLeadTraderIdIn(List<String> leadTraderId);


    // 根据交易员ID批量删除
    @Transactional
    void deleteByLeadTraderIdIn(List<String> leadTraderIds);


}
